<php> $this->display(tpl('head')); </php>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>已安装模块管理</legend>
</fieldset>
<style>
	.my-tabel thead tr td,.my-tabel tbody tr td{
		text-align: center;
	}
	.layui-form-switch{
		margin-top: 0;
	}
</style>

    <table class="layui-table my-tabel layui-form" lay-filter="test3">
    	<thead>
    		<tr>
    			<td width="50">id</td>
    			<td>模块名称</td>
    			<td>表前戳</td>
    			<td>目录</td>
    			<td>绑定域名</td>
    			<td width="70">是否在会员显示</td>
    			<td width="70">状态</td>
    			<td width="90">操作</td>
    		</tr>
    	</thead>
		<tbody>
			<foreach array="modular">
			<php>
				$_install=include_once APP_PATH.$row['dir'].DS.'install.php';
			</php> 
			<tr>
				<td>{{$row['id'] }}</td>
    			<td onclick=" return edit_input(this,'模块名称','name')" id="name_{{$row['id'] }}" iid="{{$row['id'] }}">{{$row['name'] }}</td>
    			<td>{{$row['table'] }}</td>
    			<td>{{$row['dir'] }}</td>
    			<td onclick=" return edit_input(this,'domain','domain')" id="domain_{{$row['id'] }}" iid="{{$row['id'] }}">{{$row['domain'] }}</td>
    			<td><input type="checkbox" id="{{$row['id'] }}" {{ $row['user_show'] ? 'checked' : ''}} name="user_show"  lay-filter="user_show" lay-skin="switch"  lay-text='开启|关闭'></td>
    			
				
				<td><input type="checkbox" id="{{$row['id'] }}" {{$row['state'] ?  'checked' : ''}} name="state"  lay-filter="state" lay-skin="switch"  lay-text='开启|关闭'></td>
				
    			<td>
    				<a class="layui-btn layui-btn-xs layui-btn-normal" href="/admin/modular/copy/id_{{$row['id'] }}">复制</a>
    				<a class="layui-btn layui-btn-xs layui-btn-danger"  onclick="return confirm('您是否确定要卸载本模块？卸载以后，所有模块数据将被擦除，此方法不可逆。')"  href="/admin/modular/del/id_{{$row['id'] }}">卸载</a>
    			</td>
			</tr>
			</foreach>
		</tbody>
	</table>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>未安装模块</legend>
</fieldset>
	<table class="layui-table my-tabel layui-form" lay-filter="test3">
    	<thead>
    		<tr>
    			<td>模块名称</td>
    			<td>表前戳</td>
    			<td>目录</td>
    			<td>开发者信息</td>
    			<td>状态</td>
    			<td>版本</td>
    			<td>更新时间</td>
    			<td>操作</td>
    		</tr>
    	</thead>
		<tbody>
			<foreach array="install">
			<tr>

    			<td>{{$row['modular']['name'] }}</td>
    			<td>{{$row['modular']['table'] }}</td>
    			<td>{{$row['dir'] }}</td>
    			<td>
    				<p>开发者:{{$row['modular']['developer'] }}</p>
    				<p>联系email:{{$row['modular']['email'] }}</p>
    				<p>开发公司：{{$row['modular']['firm'] }}</p>
    			</td>
    			<td>待安装</td>
    			<td>{{$row['modular']['version'] }}</td>
    			<td>{{$row['modular']['update'] }}</td>
    			<td>
    				<a class="layui-btn layui-btn-xs layui-btn-normal" href="/admin/modular/install/dir_{{$row['dir'] }}">安装</a>
    				<a class="layui-btn layui-btn-xs layui-btn-danger"  onclick="return confirm('您是否确定要删除本模块？此方法不可逆')"  href="/admin/modular/del/step_install/dir_{{$row['dir'] }}">删除</a>
    			</td>
			</tr>
			</foreach>
		</tbody>
	</table>
<script>
function edit_input(a,b,c){
	
	$('#'+a.id).removeAttr("onclick"); 
	var iid =$('#'+a.id).attr('iid');
	a.innerHTML='<input type="text"  class="layui-input"  name="name" id="name" value="'+a.innerHTML+'" />';
	$("#name").focus();
	$("#name").blur(function(){
		var value=$(this).attr("value");
		$.ajax({
			url:"/admin/modular/edit/",
			type: 'POST',
			data:{'value':value,'id':iid,'step':c,'json':true},
			dataType: 'json',
			success: function(data){
				if(data.code=='0'){
					layer.tips('当前'+b+'修改为：'+value,a);
					$('#'+a.id).attr("onclick"," return edit_input(this)");
					a.innerHTML=data.value;
				}else{
					a.innerHTML=data.value;
					$('#'+a.id).attr("onclick"," return edit_input(this)"); 
					layer.tips(data.text, a);
				}
			}	
		});
		
		layer.tips('当前模块名称修改为：'+value,a);
	});
}

layui.use(['form','table'], function(){
	var form = layui.form;
	var table = layui.table;
	form.on('switch(subsite_show)', function(obj){
	  var subsite_show= this.checked ? '1' : '0';
		$.ajax({
			url:"/admin/modular/subsite_show/",
			type: 'POST',
			data:{'subsite_show':subsite_show,'id':this.id,'json':true},
			dataType: 'json',
			success: function(data){
				if(data.code=='0'){
					if(subsite_show==0){
						layer.tips("已关闭分站管理中心显示功能", obj.othis);
					}else{
						layer.tips("已开启分站管理显示功能", obj.othis);
				  }
				}else{
					layer.tips(data.text, obj.othis);
				}
			}	
		});
	});
	//监听指定开关
	form.on('switch(state)', function(obj){
	  	var state= this.checked ? '1' : '0';
		$.ajax({
			url:"/admin/modular/state/",
			type: 'POST',
			data:{'state':state,'id':this.id,'json':true},
			dataType: 'json',
			success: function(data){
				console.log(data);
				if(data.code=='0'){
					if(state==0){
						layer.tips("本模块已关闭", obj.othis);
					}else{
						layer.tips("本模块已开启", obj.othis);
				  	}
				}else{
					layer.tips(data.text, obj.othis);
				}
			
				
			}	
		});
	   
	});
	form.on('switch(user_show)', function(obj){
	  var user_show= this.checked ? '1' : '0';
		$.ajax({
			url:"/admin/modular/user_show/",
			type: 'POST',
			data:{'user_show':user_show,'id':this.id,'json':true},
			dataType: 'json',
			success: function(data){
				if(data.code=='0'){
					if(user_show==0){
						layer.tips("已关闭前台显示功能", obj.othis);
					}else{
						layer.tips("已开启前台显示功能", obj.othis);
				  }
				}else{
					layer.tips(data.text, obj.othis);
				}
			}	
		});
	});

});

</script>
<php> $this->display(tpl('foot')); </php>
